You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

[...nextauth].ts 887B

1234567891011121314151617181920212223242526272829303132333435
  1. import { isSponsoringMe } from 'utils/isSponsoringMe'
  2. import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
  3. import NextAuth from 'next-auth'
  4. import Providers from 'next-auth/providers'
  5. export default function Auth(
  6. req: NextApiRequest,
  7. res: NextApiResponse
  8. ): ReturnType<NextApiHandler> {
  9. return NextAuth(req, res, {
  10. providers: [
  11. Providers.GitHub({
  12. clientId: process.env.GITHUB_ID,
  13. clientSecret: process.env.GITHUB_SECRET,
  14. scope: 'read:user',
  15. }),
  16. ],
  17. callbacks: {
  18. async redirect(url, baseUrl) {
  19. return baseUrl
  20. },
  21. async signIn(user, account, profile: { login?: string }) {
  22. if (profile?.login) {
  23. const canLogin = await isSponsoringMe(profile.login)
  24. if (canLogin) {
  25. return canLogin
  26. }
  27. }
  28. return '/'
  29. },
  30. },
  31. })
  32. }